package org.lanqiao.api.collect;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.CartListPOJO;
import org.lanqiao.pojo.CollectPOJO;
import org.lanqiao.service.CartServiceImpl;
import org.lanqiao.service.CollectServieImpI;


/**
 * 加入收藏接口的实现
 * @author dzp
 *
 */
@WebServlet("/api/collect/add")

public class AddCollectServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
		JsonResult result=null;
		CollectServieImpI addCollectServie = new CollectServieImpI();
		//加入收藏传入参数,   	 	    
	    String userId = request.getParameter("UserId");
		String productId = request.getParameter("ProductId");
		String productPhoto = request.getParameter("ProductPhoto");
		String productPrice = request.getParameter("ProductPrice");
		
		CollectPOJO collectlist = new CollectPOJO();
		collectlist.setUserId(userId);
		collectlist.setProductId(productId);
		collectlist.setProductPhoto(productPhoto);
		collectlist.setProductPrice(productPrice);
		int a = addCollectServie.add(collectlist);

		
		try {
			if(a>0){				
				result=new JsonResult<String>("加入收藏成功",Constants.STATUS_SUCCESS);
			}else {				
				result=new JsonResult<String>("加入失败",Constants.STATUS_UNFOUND);
			}
		} catch (Exception e) {			
			result=new JsonResult<String>("加入异常",Constants.STATUS_FAILURE);
		}
		
		JsonResultWriter.writer(response, result);
		
	}


}